home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / iref.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  9KB  |  233 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* iref.h */
  20. /* Object structure and type definitions for Ghostscript */
  21.  
  22. /* The typedef for object references */
  23. typedef struct ref_s ref;
  24.  
  25. /*
  26.  * Object types.  The types marked with + use the read/write/execute
  27.  * attributes; the rest only use the executable attribute.
  28.  * The types marked with # are composite and hence use the a_local attribute;
  29.  * objects of all other types must have a_local cleared.
  30.  */
  31. typedef enum {
  32.  
  33.         /* NOTE: The first 4 types must be kept together */
  34.         /* for the sake of r_is_array and r_is_proc (see below). */
  35.  
  36. #define _t_array_span 4
  37.     t_array,        /* # + value.refs, uses size */
  38.         /* The following are the two implementations of */
  39.         /* packed arrays. */
  40.     t_mixedarray,        /* # + value.packed, uses size */
  41.     t_shortarray,        /* # + value.packed, uses size */
  42.       t_unused_array_,    /*     (an unused array type) */
  43.  
  44.     t_boolean,        /*     value.index */
  45.     t_condition,        /* #   value.pcond */
  46.     t_dictionary,        /* # + value.pdict */
  47.     t_file,            /* # + value.pfile, uses size for id */
  48.     t_fontID,        /* #   value.pfont */
  49.     t_gstate,        /* #   value.pgstate */
  50.     t_integer,        /*     value.intval */
  51.     t_lock,            /* #   value.plock */
  52.     t_mark,            /*       (no value) */
  53.     t_name,            /*     value.pname, uses size for index */
  54.     t_null,            /*     (value.opproc, uses size for mark */
  55.                 /*       type, on e-stack only) */
  56.     t_operator,        /*     value.opproc, uses size for index */
  57.     t_real,            /*     value.realval */
  58.     t_save,            /* #   value.psave */
  59.     t_string,        /* # + value.bytes, uses size */
  60. /*
  61.  * The following are extensions to the PostScript type set.
  62.  * When adding new types, be sure to edit the table in gs_init.ps
  63.  * (==only operator), the printing routine in idebug.c, the dispatch
  64.  * in interp.c, obj_eq in iutil.c, restore_check_stack in zvmem.c,
  65.  * and also type_name_strings and type_print_strings below.
  66.  */
  67.     t_device,        /* #    value.pdevice */
  68.     t_oparray,        /* #      (no value), uses size for index */
  69.     t_next_index    /*** first available index ***/
  70. } ref_type;
  71. /*
  72.  * The interpreter uses types starting at t_next_index for representing
  73.  * a few high-frequency operators.
  74.  * Since there are no operations specifically on operators,
  75.  * there is no need for any operators to check specifically for these
  76.  * types.  The r_btype macro takes care of the conversion when required.
  77.  */
  78. extern const int tx_next_index;
  79. /*
  80.  * Define the types that use the size field.
  81.  */
  82. #define case_types_with_size\
  83.   case t_array: case t_file: case t_name: case t_operator: case t_string:\
  84.   case t_mixedarray: case t_shortarray: case t_oparray
  85. /*
  86.  * Define the type names for debugging printout.
  87.  * All names must be the same length, so that columns will line up.
  88.  */
  89. #define type_print_strings\
  90.   "arry","mpry","spry","u?ry",\
  91.   "bool","cond","dict","file",\
  92.   "font","gsta","int ","lock","mark",\
  93.   "name","null","oper","real","save",\
  94.   "str ","devc","opry"
  95. /*
  96.  * Define the type names for the type operator.
  97.  */
  98. #define type_name_strings\
  99.   "arraytype","packedarraytype","packedarraytype","arraytype",\
  100.   "booleantype","conditiontype","dicttype","filetype",\
  101.   "fonttype","gstatetype","integertype","locktype","marktype",\
  102.   "nametype","nulltype","operatortype","realtype","savetype",\
  103.   "stringtype","devicetype","operatortype"
  104.  
  105. /*
  106.  * The following factors affect the encoding of attributes:
  107.  *
  108.  *    - The packed array format requires the high-order bits of the
  109.  *      type/attributes field to be 0.  (see packed.h)
  110.  *
  111.  *    - The interpreter wants the type, executable bit, and execute
  112.  *      permission to be adjacent, and in that order from high to low.
  113.  *
  114.  *    - Type testing is most efficient if the type is in a byte by itself.
  115.  *
  116.  * The layout given below results in the most efficient code overall.
  117.  */
  118.  
  119. /* Location attributes. */
  120. /* Note that these are associated with the *location*, not with the */
  121. /* ref that is *stored* in that location. */
  122. #define l_mark 2            /* mark for garbage collector */
  123.                     /* (not used yet) */
  124. #define l_new 4                /* stored into since last save */
  125. /* Attributes visible at the PostScript language level. */
  126. #define a_local 8            /* object allocated in local VM */
  127. #define a_write 0x10
  128. #define a_read 0x20
  129. #define a_execute 0x40
  130. #define a_executable 0x80
  131. #define a_readonly (a_read+a_execute)
  132. #define a_all (a_write+a_read+a_execute)
  133. #define r_type_shift 8
  134. #define r_type_bits 6
  135.  
  136. /* Define the attribute names for debugging printout. */
  137. #define attr_print_string "?mnlwrxe......??"
  138.  
  139. /* Abstract types */
  140. typedef struct dict_s dict;
  141. typedef struct name_s name;
  142. /* We define a dummy type for op_proc_p so that */
  143. /* we don't have to include oper.h. */
  144. typedef int (*dummy_op_proc_p)();
  145. #define real_opproc(pref) (*(op_proc_p *)&(pref)->value)
  146.  
  147. /* Object reference */
  148. /*
  149.  * Note that because of the way packed arrays are represented,
  150.  * the type_attrs member must be the first one in the ref structure.
  151.  */
  152. struct stream_s;
  153. struct gs_font_s;
  154. struct gs_condition_s;
  155. struct gs_lock_s;
  156. struct gx_device_s;
  157. struct gstate_obj_s;
  158. struct vm_save_s;
  159. struct tas_s {
  160.     ushort type_attrs;
  161.     ushort rsize;
  162. };
  163. struct ref_s {
  164.  
  165.     struct tas_s tas;
  166.  
  167. #define r_size(rp) ((rp)->tas.rsize)
  168. #define r_inc_size(rp,inc) ((rp)->tas.rsize += (inc))
  169. #define r_set_size(rp,siz) ((rp)->tas.rsize = (siz))
  170. /* type_attrs is a single element for fast dispatching in the interpreter */
  171. #if r_type_shift == 8
  172. #  if arch_is_big_endian
  173. #    define r_type(rp) (((byte *)&((rp)->tas.type_attrs))[sizeof(ushort)-2])
  174. #  else
  175. #    define r_type(rp) (((byte *)&((rp)->tas.type_attrs))[1])
  176. #  endif
  177. #  define r_has_type(rp,typ) (r_type(rp) == (typ))
  178. #else
  179. #  define r_type(rp) ((rp)->tas.type_attrs >> r_type_shift)
  180. #  define r_has_type(rp,typ) r_has_type_attrs(rp,typ,0)    /* see below */
  181. #endif
  182. /* A special macro for testing arrayhood. */
  183. #define r_is_array(rp) _r_has_masked_type_attrs(rp,t_array,_t_array_span,0)
  184. #define r_set_type(rp,typ) ((rp)->tas.type_attrs = (typ) << r_type_shift)
  185. #define r_btype(rp)\
  186.  ((rp)->tas.type_attrs >= (t_next_index << r_type_shift) ?\
  187.   t_operator : r_type(rp))
  188. #define type_xe(tas) ((tas) >> (r_type_shift - 2))
  189. #define r_type_xe(rp) type_xe((rp)->tas.type_attrs)
  190. #define type_xe_value(t,xe) type_xe(((t) << r_type_shift) + (xe))
  191. #define r_type_attrs(rp) ((rp)->tas.type_attrs)    /* reading only */
  192. #define r_has_attrs(rp,mask) !(~r_type_attrs(rp) & (mask))
  193. #define r_has_attr(rp,mask1)        /* optimize 1-bit case */\
  194.    (r_type_attrs(rp) & (mask1))
  195. /* The following macro is not for external use. */
  196. #define _r_has_masked_type_attrs(rp,typ,tspan,mask)\
  197.  (((rp)->tas.type_attrs &\
  198.    ((((1 << r_type_bits) - (tspan)) << r_type_shift) + (mask))) ==\
  199.   (((typ) << r_type_shift) + (mask)))
  200. #define r_has_type_attrs(rp,typ,mask)\
  201.   _r_has_masked_type_attrs(rp,typ,1,mask)
  202. /* A special macro for testing procedurehood. */
  203. #define r_is_proc(rp)\
  204.   _r_has_masked_type_attrs(rp,t_array,_t_array_span,a_execute+a_executable)
  205. #define r_set_attrs(rp,mask) ((rp)->tas.type_attrs |= (mask))
  206. #define r_clear_attrs(rp,mask) ((rp)->tas.type_attrs &= ~(mask))
  207. #define r_set_type_attrs(rp,typ,mask)\
  208.  ((rp)->tas.type_attrs = ((typ) << r_type_shift) + (mask))
  209.  
  210.     union v {            /* name the union to keep gdb happy */
  211.         long intval;
  212.         ushort index;        /* for enumerated things */
  213.         float realval;
  214.         byte *bytes;
  215.         const byte *const_bytes;
  216.         ref *refs;
  217.         const ref *const_refs;
  218.         name *pname;
  219.         const name *const_pname;
  220.         dict *pdict;
  221.         const dict *const_pdict;
  222.         const ushort /*ref_packed*/ *packed;
  223.         dummy_op_proc_p opproc;
  224.         struct stream_s *pfile;
  225.         struct gs_font_s *pfont;
  226.         struct gs_condition_s *pcond;
  227.         struct gs_lock_s *plock;
  228.         struct gx_device_s *pdevice;
  229.         struct gs_state_s *pgstate;
  230.         struct vm_save_s *psave;
  231.     } value;
  232. };
  233.